import React, {PureComponent} from 'react';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import classnames from 'classnames';

// import utils from '../../utils';
// import routes from '../../routes';
// import {leaveToPage, lineLoadingOver, lineLoading} from '../../ducks/actions';

import './index.less';

export default class LinkWrapper extends PureComponent {

    static contextTypes = {
        store: PropTypes.any,
        router: PropTypes.any
    };

    // handleClick = async e => {
    //     const {store, router} = this.context;
    //     const {to: location, lineLoading, lineLoadingOver, leaveToPage} = this.props;

    //     lineLoading();

    //     try {
    //         await Promise.all(utils.getDataPromises(store.dispatch, location, routes));
    //     }
    //     catch (err) {}

    //     (document.documentElement || document.body).scrollTop = 0;

    //     setTimeout(()=> {
    //         lineLoadingOver();

    //         router.history.push(location);

    //         leaveToPage(location, router.route.match.path);
    //     }, 200);
    // };

    handleClick = e => {
        const location = this.props.to;

        this.context.router.history.push(location);
    };

    render() {
        return (
            <div
                className={classnames(this.props.className, 'link')}
                onClick={this.handleClick}
                style={this.props.styles}
            >
                {this.props.children}
            </div>
        );
    }
}

// function mapDispatchToProps(dispatch) {
//     return {
//         leaveToPage(path, srcPath) {
//             return dispatch(leaveToPage(path, srcPath));
//         },
//         lineLoading() {
//             return dispatch(lineLoading());
//         },
//         lineLoadingOver() {
//             return dispatch(lineLoadingOver());
//         },
//         ajaxFail(data) {
//             return dispatch(ajaxFail(data));
//         }
//     };
// }

// export default connect(null, mapDispatchToProps)(LinkWrapper);

